package com.jmz.qyyl.controller;

import com.jmz.qyyl.domain.URole;
import com.jmz.qyyl.mapper.URoleMapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by ZMY on 2018年02月28日
 * @Author:zmy
 */
@RestController
public class URoleController {
  @Autowired
  URoleMapper uRoleMapper;




  @ApiOperation(value = "获取所有用户列表", notes = "")
  @RequestMapping(value = {"getURoleList"}, method = RequestMethod.GET)
  public List<URole> getURoleList() {
    List<URole> r = uRoleMapper.selectAll();
    return r;
  }
  


  @ApiOperation(value = "删除已存在的用户", notes = "根据url的id来指定删除对象")
  @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
  @RequestMapping(value = "/deleteURole/{id}", method = RequestMethod.DELETE)
  public String deleteURole(@PathVariable Long id) {
    uRoleMapper.deleteByPrimaryKey(id);
    return "success";
  }

  @ApiOperation(value = "获取用户详细信息", notes = "根据url的id来获取用户详细信息")
  @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
  @RequestMapping(value = "/getURole/{id}", method = RequestMethod.GET)
  public URole getURole(@PathVariable Long id) {
    return uRoleMapper.selectByPrimaryKey(id);
  }


  @ApiOperation(value = "创建新的用户", notes = "根据URole对象创建用户")
  @ApiImplicitParam(name = "URole", value = "用户详细实体URole", required = true, dataType = "URole")
  @RequestMapping(value = "/postURole", method = RequestMethod.POST)
  public String postURole(@RequestBody URole uRole) {
    uRoleMapper.updateByPrimaryKey(uRole);
    return "success";
  }

  @ApiOperation(value = "更新用户详细信息", notes = "根据url的id来指定更新对象")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
      @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
  })
  @RequestMapping(value = "/putUser/{id}", method = RequestMethod.PUT)
  public String putUser(@PathVariable Long id, @RequestBody URole uRole) {
    URole u = uRoleMapper.selectByPrimaryKey(uRole.getId());
    u.setName(uRole.getName());
    u.setType(uRole.getType());
    uRoleMapper.updateByPrimaryKey(uRole);
    return "success";
  }


}
